Protecting from crashes (beyond bounds) with [object objectAtIndex:]

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-06-02T15:49:56Z Indexed on 2010/06/02 15:54 UTC
Read the original article Hit count: 107

Filed under:
|

Hi!

I'd like to know if there's a way to verify if an index exists before getting it.

So it'd be way to protect my code against:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (0)'

Like in PHP you can do: isset($object[10]); and it'll return true if it exists.

Is there such a method in Objective-C/Cocoa?

Thanks!

© Stack Overflow or respective owner

Related posts about cocoa-touch

Related posts about arrays